﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using BathhouseService.Models.SqlModels;
using BathhouseService.Models.FrameEnumeration;

namespace BathhouseService.CURD.ViewModels.RechargeRecordVMs
{
    public partial class RechargeRecordListVM : BasePagedListVM<RechargeRecord_View, RechargeRecordSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("RechargeRecord", GridActionStandardTypesEnum.Create, "发卡","CURD", dialogWidth: 800,name:"发卡"),
                this.MakeStandardAction("RechargeRecord", GridActionStandardTypesEnum.Edit, "退卡","CURD", dialogWidth: 800,name:"办理退卡"),
                this.MakeStandardAction("RechargeRecord", GridActionStandardTypesEnum.Delete, "修改支付金额","CURD", dialogWidth: 800,name:"修改支付金额").SetBindVisiableColName("CanEdit"),
            };
        }
        protected override IEnumerable<IGridColumn<RechargeRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<RechargeRecord_View>>{
                this.MakeGridHeader(x => x.OrderId),
                this.MakeGridHeader(x => x.ServicePersonName),
                this.MakeGridHeader(x => x.CustomerName),
                this.MakeGridHeader(x => x.PaymentTime),
                this.MakeGridHeader(x => x.Name_view),
                this.MakeGridHeader(x => x.ActualPayment),
                this.MakeGridHeader(x => x.HandlTypeEnums_view).SetForeGroundFunc((entity)=> {
                if(entity.HandlTypeEnums_view == "退卡")
                {
                    return "FF0000";
                }else
                {
                    return "008000" ;
                }
            }),
                this.MakeGridHeader(x=>"CanEdit").SetHide().SetFormat((e,v)=>{
                    if (e.HandlTypeEnums_view == "退卡"){
                        return "false";
                    }
                    else {
                        return "true";
                    }
                }),
                this.MakeGridHeader(x => x.PayWay_view),
                this.MakeGridHeaderAction(width: 200)
            };
        }
        public override IOrderedQueryable<RechargeRecord_View> GetSearchQuery()
        {
            var query = DC.Set<RechargeRecord>()
                .CheckContain(Searcher.OrderId, x => x.OrderId)
                .CheckContain(Searcher.ServicePersonName, x => x.ServicePersonName)
                .CheckContain(Searcher.CustomerName, x => x.CustomerName)
                .CheckBetween(Searcher.PaymentTime?.GetStartTime(), Searcher.PaymentTime?.GetEndTime(), x => x.PaymentTime, includeMax: false)
                .Select(x => new RechargeRecord_View
                {
                    ID = x.ID,
                    OrderId = x.OrderId,
                    ServicePersonName = x.ServicePersonName,
                    CustomerName = x.CustomerName,
                    PaymentTime = x.PaymentTime,
                    Name_view = x.PackageService.Name,
                    ActualPayment = x.ActualPayment,
                    HandlTypeEnums_view = ((HandlTypeEnum)x.HandlTypeEnums).ToString(),
                    PayWay_view = x.PayWay.Names
                })
                .OrderByDescending(x => x.ID);
            return query;
        }
    }
    public class RechargeRecord_View : RechargeRecord
    {
        [Display(Name = "套餐名称")]
        public String Name_view { get; set; }
        [Display(Name = "类型")]
        public string HandlTypeEnums_view { get; set; }
        [Display(Name = "支付方式")]
        public string PayWay_view { get; set; }

    }
}
